package com.bw.inspection.page

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.a_zg3_zxm01.park.xjgl.xjXq.BzAdapter
import com.bw.a_zg3_zxm01.park.xjgl.xjXq.DwAdapter
import com.bw.a_zg3_zxm01.park.xjgl.xjXq.GdAdapter
import com.bw.base.path.RouterPath
import com.bw.common.view.BaseMvvmActivity
import com.bw.common.vm.BaseViewModel
import com.bw.inspection.R
import com.bw.inspection.databinding.ActivityDetailNoInspenctionBinding
import com.bw.inspection.vm.InspectionViewModel
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouterPath.PATH_DETAIL_NO_INSPECTION_PATH)
@AndroidEntryPoint
class DetailNoInspenctionActivity : BaseMvvmActivity<ActivityDetailNoInspenctionBinding>() {
    @JvmField
    @Autowired
    var tid = 0
    var dwAdapter = DwAdapter()
    var gdAdapter = GdAdapter()


    private val mViewModel : InspectionViewModel by viewModels()
    override fun getLayoutId(): Int =R.layout.activity_detail_no_inspenction

    override fun initViews() {
        super.initViews()
        ARouter.getInstance().inject(this)
        mDataBinding.ivBack.setOnClickListener { finish() }
        mViewModel.getInspectionDetailData(tid)
        mDataBinding.rv.adapter = dwAdapter
        mDataBinding.tab.addTab(mDataBinding.tab.newTab().setText("点位信息"))
        mDataBinding.tab.addTab(mDataBinding.tab.newTab().setText("跟踪信息"))
        val list = listOf(
            ItemEntity("西区游乐场", "游乐场", "未巡检》"),
            ItemEntity("东区健身区", "健身区", "未巡检》"),
            ItemEntity("南区游泳池", "游泳池", "未巡检》"),
        )

        dwAdapter.setList(list)

        mDataBinding.tab.addOnTabSelectedListener(object: OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab?) {
                when(tab?.position){
                    0->{
                        mDataBinding.rv.adapter = dwAdapter
                        mDataBinding.assignTasks.visibility= View.VISIBLE
                        mDataBinding.assignTasks.setOnClickListener {
                            mDataBinding.startInspection.visibility=View.VISIBLE
                            mDataBinding.transfer.visibility=View.VISIBLE
                            mDataBinding.assignTasks.visibility=View.GONE
                        }
                    }

                    1->{
                        mDataBinding.ll.visibility=View.GONE
                        val list1 = listOf<String>(
                            "暂无数据",
                        )
                        mDataBinding.rv.adapter = gdAdapter
                        gdAdapter.data.clear()
                        gdAdapter.addData(list1)
                        gdAdapter.notifyDataSetChanged()

                        mDataBinding.assignTasks.visibility= View.GONE
                    }
                }
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }

            override fun onTabReselected(tab: TabLayout.Tab?) {
            }

        })



    }

    override fun loadData() {
        super.loadData()
        mViewModel.mPatrolDetailSuccess.observe(this){
            mDataBinding.taskName.text = it.taskName
            mDataBinding.patrolTime.text = it.patrolTime
        }
    }
}

data class ItemEntity(
    val name:String,
    val address:String,
    val status:String
)
